// import 'cryptojs/cryptojs';
// import Crypto from 'crypto-js/crypto-js'
var Crypto = require("crypto-js");

// 字符串加解密
var woutlaCrypto = {
    // MD5 摘要
    md5:function(str){
        return Crypto.MD5(str).toString();
    },

    // AES 对称加密算法
    /**
     * [encrypt 加密]
     * @return {[type]} [description]
     */
    encrypt: function (content,key) {
      console.log("即将加密内容：", content,"指定加密KEY:", key);
        if(!key)
            key = "wallet!^@$!@";
        var encryptResult = Crypto.AES.encrypt(content, key);
        console.log("加密后结果：",encryptResult.toString());
        return encryptResult.toString();
    },
    /**
     * [decrypt 解密]
     * @return {[type]} [description]
     */
    decrypt:function (content,key) {
      console.log("即将解密内容：", content,"指定解密KEY:", key);
        if(!key)
          key = "wallet!^@$!@";
        var bytes = Crypto.AES.decrypt(content, key);
        var originalText = bytes.toString(Crypto.enc.Utf8);
      console.log("解密后结果：",originalText);
        return originalText;
    }
};

export default woutlaCrypto;
